package com.pmstation.skin

import scala.math._

case class XY(x:Int, y:Int){
  def dx(p:XY) = p.x-x
  def dy(p:XY) = p.y-y
  def dist(p:XY) = sqrt(dx(p)*dx(p) + dy(p)*dy(p))
  def +(p:XY) = XY(x+p.x, y+p.y)
  def shift(dx:Double,dy:Double) = XY(x+dx.toInt, y+dy.toInt)
  def shiftRadial(step:Int, radians: Double) = shift(step*cos(radians),step*sin(radians))
  def middle(p:XY) = XY((x+p.x)/2, (y+p.y)/2)
  def angle(p:XY) = atan2( p.y-y, p.x-x )

  def xMost(other:XY) = if(other.x>x) other else this
  def xLeast(other:XY) = if(other.x<x) other else this
  def yMost(other:XY) = if(other.y>y) other else this
  def yLeast(other:XY) = if(other.y<y) other else this
}
